package com.project.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.BuyOrderBean;
import com.project.mapper.IBuyOrderMapper;
import com.project.service.IBuyOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class BuyOrderServiceImp implements IBuyOrderService {
    @Autowired
    private IBuyOrderMapper mapper;
    @Override
    public void add(BuyOrderBean buyOrderBean) {
        mapper.insert(buyOrderBean);
    }

    @Override
    public IPage<BuyOrderBean> cutByItem(Integer pageNO, String name, LocalDate startDate, LocalDate endDate) {
        QueryWrapper qw =new QueryWrapper<>();
        if(name!=null&& name.length()!=0) {
            qw.like("o_supplierName",name);
        }
        if(startDate!=null){
            qw.ge("o_date",startDate);
        }
        if(startDate!=null){
            qw.le("o_date",endDate);
        }
        return mapper.selectPage(new Page<>(pageNO,5),qw);
    }
}
